﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using DTO;

namespace BUS
{
    public class BaoCaoBUS
    {
        public static void themBaoCao (long maphong,string tenloaiphong,string ngaybd,int songay,double tien,string ngaylaphoadon) 
        {
            DAO.BaoCaoDAO.themBaoCao(maphong, tenloaiphong, ngaybd, songay, tien,ngaylaphoadon);
        }
        public static List<BaoCaoDTO> layDSBaoCaoTheoThangvaNam(string thang, string nam)
        {
            return DAO.BaoCaoDAO.layDSBaoCaoTheoThangvaNam(thang,nam);
        }
        public static bool Kiemtra(List<BaoCaoDTO> ds,string tenloaiphong)
        {
            for(int i=0;i<ds.Count;i++)
            {
                if(ds[i].TenLoaiPhong == tenloaiphong)
                    return true;
            }
            return false;
        }
        public static List<BaoCaoDTO> thongKeTheoLoaiPhong(List<BaoCaoDTO> ds)
        {
            List<BaoCaoDTO> dsLoaiPhong = new List<BaoCaoDTO>();
            BaoCaoDTO tam = ds[0];
            dsLoaiPhong.Add(tam);
            for(int i =1;i<ds.Count;i++)
            {
                if(Kiemtra(dsLoaiPhong,ds[i].TenLoaiPhong)== false)
                    dsLoaiPhong.Add(ds[i]);
                else
                    for(int j =0 ;j<dsLoaiPhong.Count;j++)
                        if(ds[i].TenLoaiPhong==dsLoaiPhong[j].TenLoaiPhong)
                            dsLoaiPhong[j].ThanhTien += ds[i].ThanhTien;
            }
            return dsLoaiPhong;
        }
        public static bool KiemtraMaPhong(List<BaoCaoDTO> ds, long maPhong)
        {
            for (int i = 0; i < ds.Count; i++)
            {
                if (ds[i].MaPhong == maPhong)
                    return true;
            }
            return false;
        }
        public static List<BaoCaoDTO> thongKeTheoPhong(List<BaoCaoDTO> ds)
        {
            List<BaoCaoDTO> dsLoaiPhong = new List<BaoCaoDTO>();
            BaoCaoDTO tam = ds[0];
            dsLoaiPhong.Add(tam);
            for (int i = 1; i < ds.Count; i++)
            {
                if (KiemtraMaPhong(dsLoaiPhong, ds[i].MaPhong) == false)
                    dsLoaiPhong.Add(ds[i]);
                else
                    for (int j = 0; j < dsLoaiPhong.Count; j++)
                        if (ds[i].MaPhong == dsLoaiPhong[j].MaPhong)
                            dsLoaiPhong[j].SoNgayThue += ds[i].SoNgayThue;
            }
            return dsLoaiPhong;
        }
    }
}
